﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace iLangl
{
	public class ErrorsResponseContext : BaseResponseContext
	{
		IList<IError> errors = null;
		public override void SetContext(object context)
		{
			base.SetContext(context);


			errors = new List<IError>();

			XmlNode errorsnode = document.SelectSingleNode("//Errors");

			ParseExtendedInfo(errorsnode);

			XmlNodeList nerrors = document.SelectNodes("//Errors/Error");

			if (nerrors != null)
				foreach (XmlNode node in errors)
				{
					Error error = new Error();

					if (node.Attributes["message"] != null)
						error.Message = node.Attributes["message"].Value;

					if (node.Attributes["description"] != null)
						error.Description = node.Attributes["description"].Value;

					if (node.Attributes["severity"] != null)
						error.Severity = ErrorSeverity.GetSeverity(node.Attributes["severity"].Value);

					errors.Add(error);
				}
		}

		public override object GetContext()
		{
			return errors;
		}
	}
}